﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
using PreeRegisterModel;
using System.Collections.Specialized;
using PreeRegisterBLL;
using PreeRegisterBLL.Security;

namespace PreeRegister_WebAPI.Controllers
{
    public class depositController : ApiController
    {
        [HttpPost]
        /// <summary>
        /// 交住院押金
        /// http://172.30.0.131:10018/api/order/getorder
        /// http://192.168.1.131:8080/api/order/getorder
        /// jsonData={"head":{"token":"","version":"","fromtype":"","sessionid":"","time":""},"body":{"atype":"1","iid":"5374407","inum":"4","oid":"1505280001","wid":"213642","time":"2015-06-01 7:00:00","card":"142625198302183914","gender":"1","birth":"1982-08-03","addr":"太原市","cid":"","ctype":"","name":"张三","tel":"11111111111","ptype":"3","rtype":"1","source":"2"}}
        /// </summary>
        /// <param name="any"></param>
        /// <returns></returns>
        public EncodeModel pay(NameValueCollection any)
        {
            try
            {
                //获取JSON加密参数
                string jsonData = CommonBLL.RequestGetParam("jsonData").ToString();

                DepositPayResponseModel depositPayResponseModel = new DepositPayResponseModel();

                //解密头和内容信息
                string head_json = "";
                string body_json = "";
                string ErrMsg = "";
                string ReturnBodyJson = "";
                if (!ResultDecode.DecodeResult(jsonData, "deposit|pay", ref head_json, ref body_json, ref ErrMsg))
                {
                    depositPayResponseModel = new DepositPayResponseModel();
                    depositPayResponseModel.code = "0";
                    depositPayResponseModel.msg = "充值押金失败:" + ErrMsg;

                    //序列化返回内容类
                    ReturnBodyJson = csSerialize.DepositPayResponseModel(depositPayResponseModel);

                    //加密返回内容Json
                    return ResultDecode.EncodeResult(ReturnBodyJson);
                }

                //入口参数日志
                CommonBLL.WriteLog("deposit|pay|Post|\r\n" + body_json + "\r\n\r\n");

                //反序列化请求字符串
                DepositPayRequestModel depositPayRequestModel = csSerialize.DepositPayRequestModel(body_json);

                //执行预约
                depositPayResponseModel = DepositPayBLL.DepositPay(depositPayRequestModel);

                //序列化返回内容类
                ReturnBodyJson = csSerialize.DepositPayResponseModel(depositPayResponseModel);

                //返回参数日志
                CommonBLL.WriteLog("deposit|pay|Return|\r\n" + ReturnBodyJson + "\r\n\r\n");

                //加密返回内容Json
                return ResultDecode.EncodeResult(ReturnBodyJson);
            }
            catch (Exception err)
            {
                DepositPayResponseModel depositPayResponseModel = new DepositPayResponseModel();
                depositPayResponseModel.code = "0";
                depositPayResponseModel.msg = "充值押金失败:" + err.Message;

                //序列化返回内容类
                string ReturnBodyJson = csSerialize.DepositPayResponseModel(depositPayResponseModel);

                //返回参数日志
                CommonBLL.WriteLog("deposit|pay|Return|\r\n" + ReturnBodyJson + "\r\n\r\n");

                //加密返回内容Json
                return ResultDecode.EncodeResult(ReturnBodyJson);
            }
        }
    }
}
